<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxShopClassify;
use App\Models\WxShopClassify as ShopClassify;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxShopClassifyController extends AdminController
{

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxShopClassify(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('pic')->image('', 60);
            $grid->column('intro');
            $grid->column('parent_id');
            $grid->column('sort')->editable();
            $grid->column('is_highlight', '高亮')->switch();
            $grid->column('is_hot', '热榜')->switch();
            $grid->column('state')->switch();
            $grid->column('created_at');

            $grid->fixColumns(1);
            $grid->model()->orderBy('id', 'asc');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxShopClassify(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('intro');
            $show->field('pic');
            $show->field('parent_id');
            $show->field('sort');
            $show->field('state');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxShopClassify(), function (Form $form) {
            $form->display('id');
            $options = ShopClassify::pluck('name', 'id')->toArray();
            $options[0] = '顶级分类';
            $form->select('parent_id', '父级分类')->options($options);

            $form->text('name');
            $form->text('intro');
            $form->image('pic')->help('建议尺寸：750*750')
                ->url('files/uploads');
            $form->number('sort');
            $form->switch('state');
            $form->switch('is_highlight', '高亮');
            $form->switch('is_hot', '热榜');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
